/*------------------------------------------------------------------------
//                          Project CommonLib                           //
------------------------------------------------------------------------*/

#pragma once

#pragma warning(disable : 4996)
#include <tchar.h>
#include <strsafe.h>
#pragma warning(default : 4996)

#define CmABS   ::abs
#define MEMSET_ANSI     ::memset
#define MEMSET_UNI      ::wmemset
#if _UNICODE
    #define MEMSET MEMSET_UNI
#else
    #define MEMSET MEMSET_ANSI
#endif

#define STRLEN_ANSI     ::strlen
#define STRLEN_UNI      ::wcslen
#if _UNICODE
    #define STRLEN STRLEN_UNI
#else
    #define STRLEN STRLEN_ANSI
#endif

    
#define STRICMP_ANSI ::_stricmp
#define STRICMP_UNI   ::wcsicmp
#if _UNICODE
        #define STRICMP STRICMP_UNI
#else
    #define STRICMP STRICMP_ANSI
#endif

#define STRNCMP_ANSI ::strncmp
#define STRNCMP_UNI   ::wcsncmp
#if _UNICODE
        #define STRNCMP STRNCMP_UNI
#else
    #define STRNCMP STRNCMP_ANSI
#endif

#define STRNICMP_ANSI ::strnicmp
#define STRNICMP_UNI   ::wcsnicmp
#if _UNICODE
        #define STRNICMP STRNICMP_UNI
#else
    #define STRNICMP STRNICMP_ANSI
#endif

#define SPRINTF_ANSI    ::StringCchPrintfA
#define SPRINTF_UNI     ::StringCchPrintfW
#if _UNICODE
    #define SPRINTF SPRINTF_UNI
#else
    #define SPRINTF SPRINTF_ANSI
#endif

#define VSNPRINTF_ANSI     ::StringCchVPrintfA
#define VSNPRINTF_UNI      ::StringCchVPrintfW
#if _UNICODE
    #define VSNPRINTF VSNPRINTF_UNI
#else
    #define VSNPRINTF VSNPRINTF_ANSI
#endif

#define STRCPY_ANSI     ::StringCchCopyA    
#define STRCPY_UNI      ::StringCchCopyW
#if _UNICODE
    #define STRCPY STRCPY_UNI
#else
    #define STRCPY STRCPY_ANSI
#endif

#define VSNPRINTF_ANSI      ::StringCchVPrintfA
#define VSNPRINTF_UNI       ::StringCchVPrintfW
#if _UNICODE
    #define VSNPRINTF VSNPRINTF_UNI
#else
    #define VSNPRINTF VSNPRINTF_ANSI
#endif

    
    
#define CHAR_TO_NUMBER_ANSI ::atol
#define CHAR_TO_NUMBER_UNI ::_wtol
    

#define FCLOSE      ::fclose
#define FCLOSE_ALL  ::_fcloseall        //streamfile close
    
#define TIME64      ::_time64

#define CmVAR_ARGS_ANSI(message, length, format) \
    { \
    va_list argument; \
    va_start(argument, format); \
    VSNPRINTF_ANSI(message, length, /*_TRUNCATE,*/ format, argument); \
    va_end( argument); \
    }

#define CmVAR_ARGS_UNI(message, length, format) \
    { \
    va_list argument; \
    va_start(argument, format); \
    VSNPRINTF_UNI(message, length, /*_TRUNCATE,*/ format, argument); \
    va_end( argument); \
    }
#if _UNICODE
    #define CmVAR_ARGS CmVAR_ARGS_UNI
#else
    #define CmVAR_ARGS CmVAR_ARGS_ANSI
#endif

#define STRNCAT_ANSI     ::strncat_s
#define STRNCAT_UNI      ::wcsncat_s
#if _UNICODE
    #define STRNCAT STRNCAT_UNI
#else
    #define STRNCAT STRNCAT_ANSI
#endif

#define STRCAT_ANSI     ::strcat_s
#define STRCAT_UNI      ::wcscat_s
#if _UNICODE
    #define STRCAT STRCAT_UNI
#else
    #define STRCAT STRCAT_ANSI
#endif

#define MEMCPY_ANSI     ::memcpy_s
#define MEMCPY_UNI      ::wmemcpy_s
#if _UNICODE
    #define MEMCPY MEMCPY_UNI
#else
    #define MEMCPY MEMCPY_ANSI
#endif   

#define STRTOK_ANSI ::strtok_s
#define STRTOK_UNI   ::wcstok_s
#if _UNICODE
        #define STRTOK STRTOK_UNI
#else
    #define STRTOK STRTOK_ANSI
#endif

#define STRDAT_ANSI ::_strdate_s
#define STRDAT_UNI ::_wstrdate_s
#if _UNICODE
    #define STRDAT STRDAT_UNI
#else
    #define STRDAT STRDAT_ANSI
#endif

#define STRTIME_ANSI ::_strtime_s
#define STRTIME_UNI ::_wstrtime_s
#if _UNICODE
#define STRTIME STRTIME_UNI
#else
#define STRTIME STRTIME_ANSI
#endif

#define PRINTF_ANSI ::printf_s
#define PRINTF_UNI ::wprintf_s
#if _UNICODE
    #define PRINTF PRINTF_UNI
#else
    #define PRINTF PRINTF_ANSI
#endif


#define FOPEN_ANSI ::fopen_s
#define FOPEN_UNI ::_wfopen_s
#if _UNICODE
    #define FOPEN FOPEN_UNI
#else
    #define FOPEN FOPEN_ANSI
#endif

#define FPRINTF_ANSI ::fprintf_s
#define FPRINTF_UNI ::fwprintf_s
#if _UNICODE
    #define FPRINTF FPRINTF_UNI
#else
    #define FPRINTF FPRINTF_ANSI
#endif

#define LOCALTIME   ::_localtime64_s

//Converts an integer to a string
#define BASE_OF_VALUE 10
#define NUMBER_TO_CHAR_ANSI(value, buf)     ::_itoa_s(value, buf, STRLEN_ANSI(buf), BASE_OF_VALUE)
#define NUMBER_TO_CHAR_UNI(value, buf, size)      ::_itow_s(value, buf, size, BASE_OF_VALUE)

/*------------------------------------------------------------------------

------------------------------------------------------------------------*/
